import "./index.less";
import {Fetch} from  '../../libs/';
import {Url, md5Url} from  '../../libs/Url';
import Tabs from '../../components/tabs/';
import {connect} from 'react-redux';
import Animate from 'rc-animate';
import {parseSearch} from  '../../libs/utils';
import CSS from '../../libs/CSS'

class TodayTeach extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            active: 0,
            photo: 1
        }
    }

    componentDidMount() {
        let clientInfo = parseSearch();
        if (clientInfo && clientInfo.clientid) {
            Fetch(Url.GET_CLASS, {body: {deviceid: clientInfo.clientid}})
                .then((res)=> {
                    if (res['class'] && res['class'].classid) {
                        clientInfo['class'] = res['class'];
                        clientInfo['school'] = res['school'];
                        clientInfo['device'] = res['device'];
                        clientInfo['classroom'] = res['classroom'];
                        Fetch(Url.TODAY_TEACH, {
                            body: {
                                classid: res['class'].classid
                            }
                        })
                            .then(res=> {
                                this.setState({data: res, loaded: true});
                            })
                            .catch(e=> {
                                console.log(e)
                            });
                    } else {
                        alert('设备码没有跟班级对应，请核验!')
                    }
                })
                .catch(e=> {
                    console.log(e)
                })
        } else {
            alert('设备码不合法，请核验!')
        }
    }

    render() {
        let data = (this.state.data && this.state.data.todayTeachingPlan) ?
            this.state.data : {
            todayTeachingPlan: [{}],
            classtime: []
        };
        const t = data.todayTeachingPlan[this.state.active] || {},
            state = this.state;
        return (
            <div
                className="todayTeach clearfix">
                <div
                    className="panel-item panel1 container-border">
                    <Tabs
                        tabs={data.todayTeachingPlan}
                        onchange={(index)=> {
                            this.setState({
                                active: index
                            })
                        }}/>
                    <div className="tabs-content">
                        <div className="title">
                            <img src={require('../../imgs/todayteach/teaching_tit_cion.png')}/>
                            <div>
                                {t.name || '暂无教学计划'}
                                <div className="progress_">今日教学计划</div>
                            </div>
                        </div>
                        <div style={{position: 'relative'}}>
                            {/*<Animate
                                component=""
                                transitionName="fade"
                            >
                                {
                                    state.loaded ? null :
                                        <img key="1" src={require('../../imgs/schedule/course_bg.png')} alt=""
                                             style={{
                                                 width: '100%',
                                                 height: '100%',
                                                 position: 'absolute',
                                                 top: 0,
                                                 right: 0,
                                                 bottom: 0, left: 0
                                             }}/>
                                }
                            </Animate>*/}
                            <div className="item" style = {{fontSize: CSS.pixel(36), color: '#a0a0a0'}}>
                                {<div dangerouslySetInnerHTML={{__html: t.comment || '内容为空'}} />}
                                {/*CSS.parseHtml(t.comment) || '内容为空'*/}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        )
    }
}

const select = state => {
    return {
        clientInfo: state.clientInfo,
        [md5Url.TODAY_TEACH]: state.fetchBySubject[md5Url.TODAY_TEACH]
    }
};

export default connect(select)(TodayTeach)